from fastapi import Request, HTTPException, Body
from configs import GO_SERVICE_SECRET_KEY, ALGORITHM
import requests
import time
import base64
import json
from server.utils import decode_verify_token
from server.utils import BaseResponse
from pprint import pprint
from loguru import logger
from configs.logging_config import configure_logging
from sse_starlette.sse import EventSourceResponse

configure_logging()

# 获取音色列表
async def get_voices(
        voice_type: str = Body(..., description="欲查询音色类型，支持以下取值：system（系统音色），voice_cloning（快速复刻的音色），voice_generation（文生音色接口生成的音色），music_generation（音乐生成产生的人声或者伴奏音色），all（以上全部）。", examples=["system", "voice_cloning", "voice_generation", "music_generation", "all"], embed=True),
        request: Request = None
):

    group_id = '1934548297561678072'
    api_key = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJHcm91cE5hbWUiOiLlub_kuJzml6DmiJHmlbDlrZfnp5HmioDmnInpmZDlhazlj7giLCJVc2VyTmFtZSI6ImhhbnNodWFuZyIsIkFjY291bnQiOiJoYW5zaHVhbmdAMTkzNDU0ODI5NzU2MTY3ODA3MiIsIlN1YmplY3RJRCI6IjE5MjUxMjMyMDMxNjkwMDE1NzAiLCJQaG9uZSI6IiIsIkdyb3VwSUQiOiIxOTM0NTQ4Mjk3NTYxNjc4MDcyIiwiUGFnZU5hbWUiOiIiLCJNYWlsIjoiIiwiQ3JlYXRlVGltZSI6IjIwMjUtMDYtMTcgMTY6MjI6MTYiLCJUb2tlblR5cGUiOjEsImlzcyI6Im1pbmltYXgifQ.f8xXTzVMIjyi1ZJfuIROeIQyef1qTrOeSpEKhzsqx1H9K15my3UrUbZTAu45qegzOFM5YegvWliCLG1oRLkEuyYkgBOPm1eLAdDWCMfLB931UE1OaVk_bYsqLdV7f2MwaR_oAVkUVFaPTEX4XF-bwvbe0kVeIyYRH7aE1g_tXdUH34mRFLXEwibHhQEMilkdrk3LEa7bWIJV6zYGeIkG4x7azsSoimYPz7NHuPou7CP4sWwLuF8rECJjj30ie5kxSbovG3fRfaeHXYISULJhhBH8Jy343jwbGp4c3S7iggMp_d0EqqRGm-CVHomfg7zdxp8QDVyr2YB3SfRbR0mPUA'  # 您的MiniMax API Key
    
    url = f"https://api.minimaxi.com/v1/get_voice?GroupId={group_id}"
    headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"}
    try:
        token = decode_verify_token(request, GO_SERVICE_SECRET_KEY, ALGORITHM)
    except Exception as e:
        return BaseResponse(code=401, msg=str(e))
    
    body = {
        "voice_type": voice_type
    }
    

    response = requests.post(url, headers=headers, json=body)
    if response.status_code == 200:
        return BaseResponse(code=200, msg="success", data=response.json())
    else:
        return BaseResponse(code=401, msg="failed", data=response.json())
